import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import city from '../views/city.vue'
import Login from '../views/Login.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/city',
    name: 'city',
    component:city
  },
  {
    path: '/login',
    name: 'Login',
    component:Login
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  // console.log(to, from)   //to 要跳转的路由   from  起点路由
  console.log(to.path);
  console.log(from.path);
  if (to.path == "/login") {
    var auth = true;
    if (auth) {
      next();
    }
  } else {
    next();
  }
})
export default router
